﻿#region Using directives

using System;
using System.Collections.Generic;
using System.Text;

using Microsoft.VisualStudio.TestTools.UnitTesting;

using Weazel.Math;

#endregion

namespace Weazel.Math.Test
{
  [TestClass]
  public class TestBitManipulation
  {
    [TestMethod]
    public void TestGetBitOutOfRange()
    {
      Integer a = new Integer(16, 0x1111, false);

      try
      {
        a.GetBit(17);
        Assert.Fail("Expected IndexOfOfRangeException");
      }
      catch (IndexOutOfRangeException)
      {
      }
    }

    [TestMethod]
    public void TestGetBitSingleUnit()
    {
      Integer a = new Integer(16, 0x1111, false);
      Assert.AreEqual(true, a.GetBit(0));
      Assert.AreEqual(false, a.GetBit(1));
    }

    [TestMethod]
    public void TestSetBitOutOfRange()
    {
      Integer a = new Integer(16, 0x1111, false);

      try
      {
        a.SetBit(17);
        Assert.Fail("Expected IndexOfOfRangeException");
      }
      catch (IndexOutOfRangeException)
      {
      }
    }

    [TestMethod]
    public void TestSetBitSingleUnit()
    {
      Integer a = new Integer(16, 0x0, false);
      a.SetBit(0);
      Assert.AreEqual(1, a.ToInt());

      a.SetBit(1);
      Assert.AreEqual(3, a.ToInt());
    }

    [TestMethod]
    public void TestClearBitOutOfRange()
    {
      Integer a = new Integer(16, 0x1111, false);

      try
      {
        a.ClearBit(100);
        Assert.Fail("Expected IndexOfOfRangeException");
      }
      catch (IndexOutOfRangeException)
      {
      }
    }

    [TestMethod]
    public void TestClearBitSingleUnit()
    {
      Integer a = new Integer(16, 0x1111, false);
      a.ClearBit(0);
      Assert.AreEqual(0x1110, a.ToInt());

      a.ClearBit(1);
      Assert.AreEqual(0x1110, a.ToInt());
    }
  }
}
